#include "head.h"

// 登录界面
user_t loog_in_link(FlightSystem Flight_sys)
{
    u_node *ptr = NULL;

    char name[50];
    char pwd[50];
    int num = 3;
    int login_successful = 1; // 用来标记是否登录成功
    initscr();                // 初始化ncurses模式
    noecho();                 // 关闭回显
    curs_set(0);              // 隐藏光标
    keypad(stdscr, TRUE);     // 允许键盘映射
    while (login_successful)
    {

        // 在这里你可以添加更多代码来处理登录逻辑
        paintWindow(name, pwd, sizeof(name) - 1);
        system("clear");
        if (NULL != (ptr = find_node_name(Flight_sys.ADMIN_USER, name)))
        {
            if (!strcmp(ptr->data.passwd, pwd))
            {
                mvprintw(WINDOW_START_Y + 7, (WINDOW_WIDTH - strlen("登录成功,进入管理员界面！")) / 2, "登录成功，进入管理员界面！！");
                login_successful = 0;
                // Progress_Bar(0, 0, 10);
                return ptr->data;
            }
        }
        if (NULL != (ptr = find_node_name(Flight_sys.REGULAR_USER, name)))
        {
            if (!strcmp(ptr->data.passwd, pwd))
            {
                mvprintw(WINDOW_START_Y + 7, (WINDOW_WIDTH - strlen("登录成功,进入用户界面！")) / 2, "登录成功，进入管理员界面！！");
                login_successful = 0;
                // Progress_Bar(0, 0, 10);
                return ptr->data;
            }
        }
        if (NULL != (ptr = find_node_name(Flight_sys.SILVER_USER, name)))
        {
            if (!strcmp(ptr->data.passwd, pwd))
            {
                mvprintw(WINDOW_START_Y + 7, (WINDOW_WIDTH - strlen("登录成功,进入银卡会员界面！")) / 2, "登录成功，进入银卡会员界面！");
                login_successful = 0;
                // Progress_Bar(0, 0, 10);
                return ptr->data;
            }
        }
        if (NULL != (ptr = find_node_name(Flight_sys.GOLD_USER, name)))
        {
            if (!strcmp(ptr->data.passwd, pwd))
            {
                mvprintw(WINDOW_START_Y + 7, (WINDOW_WIDTH - strlen("登录成功,进入金卡会员界面！")) / 2, "登录成功，进入金卡会员界面！");
                login_successful = 0;
                // Progress_Bar(0, 0, 10);
                return ptr->data;
            }
        }
        if (NULL != (ptr = find_node_name(Flight_sys.PLATINUM_USER, name)))
        {
            if (!strcmp(ptr->data.passwd, pwd))
            {
                mvprintw(WINDOW_START_Y + 7, (WINDOW_WIDTH - strlen("登录成功,进入白金会员界面！")) / 2, "登录成功，进入白金会员界面！");
                login_successful = 0;
                // Progress_Bar(0, 0, 10);
                return ptr->data;
            }
        }
        if (NULL == (ptr = find_node_name(Flight_sys.ADMIN_USER, name)) || NULL == (ptr = find_node_name(Flight_sys.REGULAR_USER, name)) || NULL == (ptr = find_node_name(Flight_sys.SILVER_USER, name)) || NULL == (ptr = find_node_name(Flight_sys.GOLD_USER, name)) || NULL == (ptr = find_node_name(Flight_sys.PLATINUM_USER, name)))
        {
            mvprintw(WINDOW_START_Y + 9, 55, "登录失败，请重试！");
            refresh();
            getchar();
            num--;
        }
        if (0 == num)
        {
            printf("输入次数过多，请重新进入系统登录\n");
            exit(-1);
        }
        clear();
        mvprintw(WINDOW_START_Y + 3, WINDOW_START_X + (WINDOW_WIDTH - strlen("请输入账号") - 2) / 2 - 13, "请输入账号：");
        mvprintw(WINDOW_START_Y + 6, WINDOW_START_X + (WINDOW_WIDTH - strlen("请输入密码") - 2) / 2 - 13, "请输入密码：");
        refresh();

        // 清空用户名和密码缓冲区
        memset(name, 0, sizeof(name));
        memset(pwd, 0, sizeof(pwd));
    }
    endwin(); // 退出ncurses模式
    // return ;
}

// 写入到文件中
void F_print(u_list *list, const char *file_name)
{
    FILE *fp = fopen(file_name, "w");
    if (NULL == fp)
    {
        ERRLOG("文件创建失败");
        return;
    }
    // 光标移动到开头
    fseek(fp, 0, SEEK_SET);

    u_node *ptr = list->next;
    // 遍历写入
    for (size_t i = 0; NULL != ptr; i++)
    {
        fprintf(fp, "%s\t%s\t%d\t%d\n", ptr->data.name, ptr->data.passwd, ptr->data.IDcard, ptr->data.value);
        ptr = ptr->next;
    }

    fclose(fp);
}

// 从文件中读取
void F_scanf(u_list *list, const char *file_name)
{
    // 以只读打开
    FILE *fp = fopen(file_name, "r");
    if (NULL == fp)
    {
        ERRLOG("文件创建失败");
        return;
    }
    // 移动光标到头
    fseek(fp, 0, SEEK_SET);

    // 判断文件行数
    char ch = '0'; // 接收文件的字符
    int len = 0;   // 判断文件的行数
    while (EOF != (ch = fgetc(fp)))
    {
        if ('\n' == ch)
        {
            len++;
        }
    }

    // 移动光标到头
    fseek(fp, 0, SEEK_SET);
    user_t data;
    for (size_t i = 0; i < len; i++)
    {
        fscanf(fp, "%s\t%s\t%d\t%d\n", data.name, data.passwd, &data.IDcard, &data.value);
        insert_node(list, data, i + 1);
    }

    fclose(fp);
    return;
}

// 航班信息文件操作  从文件中读取
void F_print_M(f_list *list, const char *file_name)
{
    FILE *fp = fopen(file_name, "w");
    if (NULL == fp)
    {
        ERRLOG("文件创建失败");
        return;
    }
    // 光标移动到开头
    fseek(fp, 0, SEEK_SET);

    f_node *ptr = list->next;
    // 遍历写入
    do
    {

        fprintf(fp, "班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        ptr = ptr->next;
    } while (ptr != list->next);

    fclose(fp);
}

// 航班信息文件操作 从文件中读取
void F_scanf_M(f_list *list, const char *file_name)
{
    // 以只读打开
    FILE *fp = fopen(file_name, "r");
    if (NULL == fp)
    {
        ERRLOG("文件创建失败");
        return;
    }
    // 移动光标到头
    fseek(fp, 0, SEEK_SET);

    // 判断文件行数
    char ch = '0'; // 接收文件的字符
    int len = 0;   // 判断文件的行数
    while (EOF != (ch = fgetc(fp)))
    {
        if ('\n' == ch)
        {
            len++;
        }
    }

    // 移动光标到头
    fseek(fp, 0, SEEK_SET);
    f_data data;
    for (size_t i = 0; i < len; i++)
    {
        fscanf(fp, "班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", &data.id, data.flighttype, data.startcity, data.arrivecity, &data.starttime[0], &data.starttime[1], &data.arrivetime[0], &data.arrivetime[1], data.flytime, &data.value, &data.maxNUM, &data.leftbuyersa, &data.whetherfly);
        insert_double_node(list, data, i + 1);
    }

    fclose(fp);
    return;
}

// 设定航班信息界面
void f_set_up_menu(f_list *list)
{
    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[44m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    const char *underline = "\033[4m"; // 下划线文本
    printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
    printf("│                                                                                    │\n");
    printf("│                                   %s%s%s设定航班信息%s                                     │\n", red_bg, white_fg, bold, reset); // 标题行
    printf("│                                ─────────────────                                   │\n");                                        // 分割线
    printf("│                                                                                    │\n");
    printf("│                       1️⃣  增加航班班次       2️⃣  删除航班信息                        │\n"); // 选项行（居中对齐）
    printf("│                                                                                    │\n");
    printf("│                                                                                    │\n");
    printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
    printf("（请按数字键选择操作）                     \n");
    int option;
    scanf("%d", &option);
    if (1 == option)
    {
        system("clear");
        printf("\t\t\t\t%s%s%s增加航班信息%s\t\t\t\t\n", red_bg, white_fg, bold, reset);
        printf("请你按照以下格式输入航班信息\n\n");
        f_data data_1;
        printf("%s班次 机型 起点站 终点站 起飞时间 到达时间 飞行时间 票价 额定载客量 剩余座位 是否起飞%s\n", blue_bg, reset);
        scanf("%d %s %s %s %d %d %d %d %s %d %d %d %c", &data_1.id, data_1.flighttype, data_1.startcity, data_1.arrivecity, &data_1.starttime[0], &data_1.starttime[1], &data_1.arrivetime[0], &data_1.arrivetime[1], data_1.flytime, &data_1.value, &data_1.maxNUM, &data_1.leftbuyersa, &data_1.whetherfly);
        f_node *ptr = find_double_node_pos(list, data_1.id);
        if (NULL != ptr)
        {
            printf("已有该航班班次增加失败\n");
            return;
        }
        insert_double_node(list, data_1, 1);
    }
    else
    {
        system("clear");
        printf("\t\t\t\t%s%s%s删除航班信息%s\t\t\t\t\\n", red_bg, white_fg, bold, reset);
        print_forward_double_link_list(list);
        printf("请你输入你要删除的航班班次");
        int num;
        getchar();
        scanf("%d", &num);
        delete_double_node(list, num);
        system("clear");
        print_forward_double_link_list(list);
    }
}

// 查询航班信息界面
void qurey_menu(f_list *list)
{
    f_node *ptr = NULL;
    f_list *list_2 = init_double_link_list();
    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[34m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    const char *underline = "\033[4m"; // 下划线文本
    printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
    printf("│                                                                                    │\n");
    printf("│                                   %s%s%s查询航班信息%s                                     │\n", red_bg, white_fg, bold, reset); // 标题行
    printf("│                                ─────────────────                                   │\n");                                        // 分割线
    printf("│                                                                                    │\n");
    printf("│                       1️⃣  按照班次查询       2️⃣  按照终点站查询                      │\n"); // 选项行（居中对齐）
    printf("│                                                                                    │\n");
    printf("│                                                                                    │\n");
    printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
    printf("（请按数字键选择操作）                     \n");
    int option;
    scanf("%d", &option);
    if (1 == option)
    {
        system("clear");
        printf("\033[1;37;44m\t\t\t\t按照班次查询\t\t\t\t\033[0m\n");
        printf("请输入你要查询的班次:");
        int num;
        scanf("%d", &num);
        ptr = find_double_node_pos(list, num);
        if (NULL == ptr)
        {
            printf("没有找到有关班次为%d的航班信息\n", num);
            return;
        }
        else
        {
            printf("找到班次为%d的航班有\n", num);
            printf("┌────────┬────────────────┬──────────┬───────────┬────────────┬────────────┬──────────────┬────────┬──────────┬────────────┬──────────┐\n");

            // 表头
            printf("|  %s班次%s  |      %s机型%s      |  %s起点站%s  |   %s终点站%s  |  %s起飞时间%s  |  %s到达时间%s  |   %s飞行时间%s   |  %s票价%s  |  %s载客量%s  |  %s剩余座位%s  |  %s是否飞%s  |\n", blue_bg, reset, blue_bg, reset, blue_bg, reset, blue_bg, reset,
                   blue_bg, reset, blue_bg, reset, blue_bg, reset, blue_bg, reset,
                   blue_bg, reset, blue_bg, reset, blue_bg, reset);

            printf("└────────┴────────────────┴──────────┴───────────┴────────────┴────────────┴──────────────┴────────┴──────────┴────────────┴──────────┘\n");
            printf("     %d      %-18s%s        %s        %02d:%02d       %02d:%02d         %-13s%-10d%-10d %-10d\t%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }
    }
    else
    {
        system("clear");
        printf("\033[1;37;44m\t\t\t\t按照终点站查询\t\t\t\t\033[0m\n");
        printf("请输入你要查询的终点站:");
        char name[128];
        getchar();
        scanf("%s", name);
        list_2 = find_double_node_name(list, name);
        if (NULL == list_2)
        {
            printf("没有找到有关终点站为%s的航班信息\n", name);
            return;
        }
        else
        {
            print_forward_double_link_list(list_2);
        }
    }
}

// 修改航班信息界面
void modify_menu(f_list *list)
{
    system("clear");
    f_node *ptr = NULL;

    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[34m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    const char *underline = "\033[4m"; // 下划线文本
    printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
    printf("│                                                                                    │\n");
    printf("│                                   %s%s%s修改航班信息%s                                     │\n", red_bg, white_fg, bold, reset); // 标题行
    printf("│                                ─────────────────                                   │\n");                                        // 分割线
    printf("│                                                                                    │\n");
    printf("│                     1️⃣  修改航班班次           2️⃣  修改航班起飞时间                  │\n"); // 选项行（居中对齐）
    printf("│                                                                                    │\n");
    printf("│                     3️⃣  修改航班到达时间       4️⃣  修改航班飞行时间                  │\n"); // 选项行（居中对齐）
    printf("│                                                                                    │\n");
    printf("│                     5️⃣  航班是否起飞                                                │\n"); // 选项行（居中对齐
    printf("│                                                                                    │\n");
    printf("│                                                                                    │\n");
    printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
    printf("（请按数字键选择操作）                     \n");
    int num;
    int num_1;
    int num_2;
    int time[2];
    char time_1[10];
    char num_3;
    scanf("%d", &num);
    switch (num)
    {
    case 1:
        system("clear");
        printf("\t\t\t\t修改航班班次\t\t\t\t\n");
        printf("请输入你要修改的航班班次:");
        scanf("%d", &num_1);
        ptr = find_double_node_pos(list, num_1);
        if (NULL == ptr)
        {
            printf("没有找到班次为%d的航班信息\n", num_1);
            break;
        }
        else
        {
            printf("找到了班次为%d有关的航班信息\n", num_1);
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }
        printf("请输入修改后的航班班次:");
        scanf("%d", &num_2);
        ptr->data.id = num_2;
        printf("修改成功，修改后的航班信息为\n");
        printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        F_print_M(list, FLIGHTS_FILE);
        break;
    case 2:
        system("clear");
        printf("\t\t\t\t修改航班起飞时间\t\t\t\t\n");
        printf("请输入你要修改的航班班次:");
        scanf("%d", &num_1);
        ptr = find_double_node_pos(list, num_1);
        if (NULL == ptr)
        {
            printf("没有找到班次为%d的航班信息\n", num_1);
            break;
        }
        else
        {
            printf("找到了班次为%d有关的航班信息\n", num_1);
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }
        printf("请输入修改后航班起飞时间:");
        scanf("%d %d", &time[0], &time[1]);
        ptr->data.starttime[0] = time[0];
        ptr->data.starttime[1] = time[1];
        printf("修改成功，修改后的航班信息为\n");
        printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        F_print_M(list, FLIGHTS_FILE);
        getchar();
        break;
    case 3:
        system("clear");
        printf("\t\t\t\t修改航班到达时间\t\t\t\t\n");
        printf("请输入你要修改的航班班次:");
        scanf("%d", &num_1);
        ptr = find_double_node_pos(list, num_1);
        if (NULL == ptr)
        {
            printf("没有找到班次为%d的航班信息\n", num_1);
            break;
        }
        else
        {
            printf("找到了班次为%d有关的航班信息\n", num_1);
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }
        printf("请输入修改后航班到达时间:");
        scanf("%d %d", &time[0], &time[1]);
        ptr->data.arrivetime[0] = time[0];
        ptr->data.arrivetime[1] = time[1];
        printf("修改成功，修改后的航班信息为\n");
        printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        F_print_M(list, FLIGHTS_FILE);
        getchar();
        break;
    case 4:
        system("clear");
        printf("\t\t\t\t修改航班飞行时间\t\t\t\t\n");
        printf("请输入你要修改的航班班次:");
        scanf("%d", &num_1);
        ptr = find_double_node_pos(list, num_1);
        if (NULL == ptr)
        {
            printf("没有找到班次为%d的航班信息\n", num_1);
            break;
        }
        else
        {
            printf("找到了班次为%d有关的航班信息\n", num_1);
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }

        printf("请输入修改后航班飞行时间:");
        scanf("%s", time_1);
        strcpy(ptr->data.flytime, time_1);
        printf("修改成功，修改后的航班信息为\n");
        printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        F_print_M(list, FLIGHTS_FILE);

        break;
    case 5:
        system("clear");
        printf("\t\t\t\t航班是否起飞\t\t\t\t\n");
        printf("请输入你要修改的航班班次:");
        scanf("%d", &num_1);
        ptr = find_double_node_pos(list, num_1);
        if (NULL == ptr)
        {
            printf("没有找到班次为%d的航班信息\n", num_1);
            break;
        }
        else
        {
            printf("找到了班次为%d有关的航班信息\n", num_1);
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        }
        printf("飞机是否已经起飞(是按y，否按n)");
        getchar();
        scanf("%c", &num_3);
        ptr->data.whetherfly = num_3;
        printf("修改成功，修改后的航班信息为\n");
        printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
        F_print_M(list, FLIGHTS_FILE);
        break;
    default:
        break;
    }
    // revise_double_node_pos(list, num_1, ptr->data);
}

// 购票界面
void buy_ticket_menu(FlightSystem Flight_sys, user_t *data_2)
{
    f_node *ptr = NULL;
    print_forward_double_link_list(Flight_sys.Flight_list);
    printf("请输入你要购买的航班班次:");
    int num_1;
    scanf("%d", &num_1);
    system("clear");
    ptr = find_double_node_pos(Flight_sys.Flight_list, num_1);
    if (NULL == ptr)
    {
        printf("没有找到你需要的购买的航班班次，请你确认你要购买的航班班次\n");
        return;
    }
    if (0 >= ptr->data.leftbuyersa)
    {
        printf("您购买的航班班次已无座位，请你更换购买的班次\n");
        return;
    }
    if ('y' == ptr->data.whetherfly)
    {
        printf("您购买的航班班次已经起飞，请你更换购买的班次\n");
        return;
    }
    printf("请你确认你的航班信息\n");
    printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", ptr->data.id, ptr->data.flighttype, ptr->data.startcity, ptr->data.arrivecity, ptr->data.starttime[0], ptr->data.starttime[1], ptr->data.arrivetime[0], ptr->data.arrivetime[1], ptr->data.flytime, ptr->data.value, ptr->data.maxNUM, ptr->data.leftbuyersa, ptr->data.whetherfly);
    printf("请确认是否下单(y/n)\n");
    char num_3;
    int flag = 0;
    getchar();
    scanf("%c", &num_3);
    if ('y' == num_3)
    {
        for(int i=0;i<data_2->ticket->len;i++)
        {
            if(!strcmp(&ptr->data.starttime[0],&data_2->ticket->data[i].starttime[0]))
            {
                printf("在同一时间段您已有一张飞机票，请注意时间!\n");
                printf("如需继续购买请按y\n");
                char a;
                getchar();
                scanf("%c",&a);
                if(a=='y')
                {
                    break;
                }
                else{
                    flag=1;
                    break;
                }
            }
        }
        switch (data_2->IDcard)
        {
        case 1:
        case 2:
            if (data_2->value < ptr->data.value)
            {
                printf("账户余额不够，请您充值后再次购买\n");
                flag = 1;
                break;
            }
            data_2->value = data_2->value - ptr->data.value;
            break;
        case 3:
            if (data_2->value < ptr->data.value * 0.9)
            {
                printf("账户余额不够，请您充值后再次购买\n");
                flag = 1;
                break;
            }
            printf("您是我们的尊贵银卡会员，我们已为您的票价悄悄打上了九折优惠\n");
            data_2->value = data_2->value - ptr->data.value * 0.9;
            break;
        case 4:
            if (data_2->value < ptr->data.value * 0.8)
            {
                printf("账户余额不够，请您充值后再次购买\n");
                flag = 1;
                break;
            }
            printf("您是我们的尊贵银卡会员，我们已为您的票价悄悄打上了八折优惠\n");
            data_2->value = data_2->value - ptr->data.value * 0.8;
            break;
        case 5:
            if (data_2->value < ptr->data.value * 0.7)
            {
                printf("账户余额不够，请您充值后再次购买\n");
                flag = 1;
                break;
            }
            printf("您是我们的尊贵银卡会员，我们已为您的票价悄悄打上了七折优惠\n");
            data_2->value = data_2->value - ptr->data.value * 0.7;
            break;
        default:
            break;
        }
        if (0 == flag)
        {
            printf("下单成功，详情信息可以去我的订单查看\n");
            u_list *list_1 = gread(Flight_sys, *data_2);
            ptr->data.leftbuyersa = ptr->data.leftbuyersa - 1;
            revise_double_node_pos(Flight_sys.Flight_list, ptr->data.id, ptr->data);
            pos_insert_list(data_2->ticket, ptr->data);
            revise_node_name(list_1, data_2->name, *data_2);
            if (10000 >= data_2->value && 2 < data_2->IDcard)
            {
                printf("抱歉！！！\n由于您的余额低于10000，已自动为您降级为普通用户\n");
                revise_u_gread(Flight_sys, data_2, 2);
                scanf_file(2,Flight_sys.REGULAR_USER);
                return;
            }
            else if (10000 <= data_2->value && 15000 >= data_2->value && 3 < data_2->IDcard)
            {
                printf("抱歉！！！\n由于您的余额低于15000，已自动为您降级为银卡会员\n");
                revise_u_gread(Flight_sys, data_2, 3);
                scanf_file(3,Flight_sys.SILVER_USER);
                return;
            }
            else if (15000 <= data_2->value && 20000 >= data_2->value && 4 <  data_2->IDcard)
            {
                printf("抱歉！！！\n由于您的余额低于20000，已自动为您降级为金卡会员\n");
                revise_u_gread(Flight_sys, data_2, 4);
                scanf_file(4,Flight_sys.GOLD_USER);
                return;
            }
            scanf_file(data_2->IDcard, list_1);
        }
        else
        {
            return;
        }
    }
    else
    {
        return;
    }
}

// 退票界面
void refund_ticket_menu(FlightSystem Flight_sys, user_t *data_2, int num_4)
{
    printf_Sql_List(data_2->ticket);
    f_node *ptr = NULL;
    if (0 == data_2->ticket->len)
    {
        printf("您还没有购票，无法退票");
        return;
    }
    else
    {
        printf("请你输入要退的航班班次\n");
        int num_1;
        scanf("%d", &num_1);
        int num_2 = 0;
        ptr = find_double_node_pos(Flight_sys.Flight_list, num_1);
        num_2 = find_by_name(data_2->ticket, num_1);
        system("clear");
        if (EOF == num_2)
        {
            printf("你的订单中没有有关班次为%d的信息\n", num_2);
            printf("请您确认您的退票信息\n");
            return;
        }
        else
        {
            printf("请您确认您的退票信息\n");
            printf("班次：%d\t机型：%s\t起点站：%s\t终点站：%s\t起飞时间：%d:%d\t到达时间：%d:%d\t飞行时间：%s\t票价：%d\t额定载客量：%d\t剩余座位：%d\t是否起飞：%c\n", data_2->ticket->data[num_2].id, data_2->ticket->data[num_2].flighttype, data_2->ticket->data[num_2].startcity, data_2->ticket->data[num_2].arrivecity, data_2->ticket->data[num_2].starttime[0], data_2->ticket->data[num_2].starttime[1], data_2->ticket->data[num_2].arrivetime[0], data_2->ticket->data[num_2].arrivetime[1], data_2->ticket->data[num_2].flytime, data_2->ticket->data[num_2].value, data_2->ticket->data[num_2].maxNUM, data_2->ticket->data[num_2].leftbuyersa, data_2->ticket->data[num_2].whetherfly);
            printf("是否退票(y/n)\n");
            char num_3;
            getchar();
            scanf("%c", &num_3);
            if ('y' == num_3)
            {
                if (1 == num_4 || 2 == num_4)
                    data_2->value = data_2->value + ptr->data.value;
                if (3 == num_4)
                    data_2->value = data_2->value + ptr->data.value * 0.9;
                if (4 == num_4)
                    data_2->value = data_2->value + ptr->data.value * 0.8;
                if (5 == num_4)
                    data_2->value = data_2->value + ptr->data.value * 0.7;

                printf("退票成功\n");
                pos_del_list(data_2->ticket, num_2);
                u_list *list_1 = gread(Flight_sys, *data_2);
                revise_node_name(list_1, data_2->name, *data_2);
                ptr->data.leftbuyersa++;
                revise_double_node_pos(Flight_sys.Flight_list, ptr->data.id, ptr->data);
                if (10000 <= data_2->value && 15000 >= data_2->value && 3 > data_2->IDcard)
                {
                    printf("恭喜你余额达到银卡会员，已自动为您升级为银卡会员\n");
                    revise_u_gread(Flight_sys, data_2, 3);
                    scanf_file(3,Flight_sys.SILVER_USER);
                    return ;
                }
                if (15000 <= data_2->value && 20000 >= data_2->value && 4 > data_2->IDcard)
                {
                    printf("恭喜你余额达到金卡会员，已自动为您升级为金卡会员\n");
                    revise_u_gread(Flight_sys, data_2, 4);
                    scanf_file(3,Flight_sys.GOLD_USER);
                    return ;
                }
                if (20000 <= data_2->value && 5 > data_2->IDcard)
                {
                    printf("恭喜你余额达到白金会员，已自动为您升级为白金会员\n");
                    revise_u_gread(Flight_sys, data_2, 5);
                    scanf_file(3,Flight_sys.PLATINUM_USER);
                    return ;
                }
                scanf_file(data_2->IDcard,list_1);
            }
            return;
        }
    }
}

// 用户链表合并
u_list *u_merge(FlightSystem Flight_sys)
{
    u_list *L = init_link_list();
    L = S_List_merge(L, Flight_sys.REGULAR_USER);
    L = S_List_merge(L, Flight_sys.SILVER_USER);
    L = S_List_merge(L, Flight_sys.GOLD_USER);
    L = S_List_merge(L, Flight_sys.PLATINUM_USER);
    return L;
}

// 判断用户等级
u_list *gread(FlightSystem Flight_sys, user_t data_2)
{
    switch (data_2.IDcard)
    {
    case 1:
        return Flight_sys.ADMIN_USER;
        break;
    case 2:
        return Flight_sys.REGULAR_USER;
        break;
    case 3:
        return Flight_sys.SILVER_USER;
        break;
    case 4:
        return Flight_sys.GOLD_USER;
        break;
    case 5:
        return Flight_sys.PLATINUM_USER;
        break;
    }
    return NULL;
}

// 修改用户等级
void revise_u_gread(FlightSystem Flight_sys, user_t *ptr, int num)
{
    u_list *list_1 = gread(Flight_sys, *ptr);
    find_del_name(list_1, ptr->name);
    scanf_file(num, list_1);
    ptr->IDcard = num;
    list_1 = gread(Flight_sys, *ptr);
    insert_node(list_1, *ptr, 1);
    scanf_file(num, list_1);
}
// 管理员修改用户账号
void revise_u_name(FlightSystem Flight_sys, user_t *ptr, char *name)
{
    u_list *list_1 = gread(Flight_sys, *ptr);
    find_del_name(list_1, ptr->name);
    strcpy(ptr->name, name);
    list_1 = gread(Flight_sys, *ptr);
    insert_node(list_1, *ptr, 1);
    scanf_file(ptr->IDcard, list_1);
}
// 管理员修改用户密码
void revise_admin_pwd(FlightSystem Flight_sys, user_t *ptr, char *num)
{
    u_list *list_1 = gread(Flight_sys, *ptr);
    find_del_name(list_1, ptr->name);
    strcpy(ptr->passwd, num);
    list_1 = gread(Flight_sys, *ptr);
    insert_node(list_1, *ptr, 1);
    scanf_file(ptr->IDcard, list_1);
}
// 管理员修改用户余额
void revise_admin_count(FlightSystem Flight_sys, user_t *ptr, int num)
{
    u_list *list_1 = gread(Flight_sys, *ptr);
    find_del_name(list_1, ptr->name);
    ptr->value = num;
    list_1 = gread(Flight_sys, *ptr);
    insert_node(list_1, *ptr, 1);
    scanf_file(ptr->IDcard, list_1);
    if (10000 <= (*ptr).value && 15000 >= (*ptr).value && 3 > (*ptr).IDcard)
    {
        printf("恭喜你充值金额达到银卡会员，已自动为您升级为银卡会员\n");
        revise_u_gread(Flight_sys, ptr, 3);
        scanf_file(ptr->IDcard, Flight_sys.SILVER_USER);
        return;
    }
    if (15000 <= ptr->value && 20000 >= ptr->value && 4 > ptr->IDcard)
    {
        printf("恭喜你充值金额达到金卡会员，已自动为您升级为金卡会员\n");
        revise_u_gread(Flight_sys, ptr, 4);
        scanf_file(ptr->IDcard, Flight_sys.GOLD_USER);
        return;
    }
    if (20000 <= ptr->value && 5 > ptr->IDcard)
    {
        printf("恭喜你充值金额达到白金会员，已自动为您升级为白金会员\n");
        revise_u_gread(Flight_sys, ptr, 5);
        scanf_file(ptr->IDcard, Flight_sys.PLATINUM_USER);
        return;
    }
}
// 修改用户界面
void revise_u_menu(FlightSystem Flight_sys, user_t *data_2)
{
    u_node *ptr = NULL;
    u_list *list_1 = u_merge(Flight_sys);
    u_list *list_2 = NULL;
    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[34m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    const char *underline = "\033[4m"; // 下划线文本
    printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
    printf("│                                                                                    │\n");
    printf("│                                   %s%s%s修改普通用户%s                                     │\n", red_bg, white_fg, bold, reset); // 标题行
    printf("│                                ─────────────────                                   │\n");                                        // 分割线
    printf("│                                                                                    │\n");
    printf("│                    1️⃣  修改用户的账号            2️⃣  修改用户的密码                  │\n"); // 选项行（居中对齐）
    printf("│                                                                                    │\n");
    printf("│                    3️⃣  修改用户的余额            4️⃣  修改用户的等级                  │\n");
    printf("│                                                                                    │\n");
    printf("│                                                                                    │\n");
    printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
    printf("（请按数字键选择操作）                     \n");
    int num;
    int num_2;
    char name[128];
    char name_1[128];
    int v;
    scanf("%d", &num);
    system("clear");
    printf("\033[47;30m\t\t普通用户\t\t\n\033[0m");
    print_link_list(Flight_sys.REGULAR_USER);
    printf("\n");
    printf("\033[47;30m\t\t银卡用户\t\t\n\033[0m");
    print_link_list(Flight_sys.SILVER_USER);
    printf("\n");
    printf("\033[47;30m\t\t金卡用户\t\t\n\033[0m");
    print_link_list(Flight_sys.GOLD_USER);
    printf("\n");
    printf("\033[47;30m\t\t白金用户\t\t\n\033[0m");
    print_link_list(Flight_sys.PLATINUM_USER);
    switch (num)
    {
    case 1:
        printf("\n");
        printf("\t\t\t\t修改用户的账号\t\t\t\t\n");
        printf("请你输入要修改的账号:  ");
        scanf("%s", name_1);
        ptr = find_node_name(list_1, name_1);
        if (NULL == ptr)
        {
            printf("没有找到你要修改的账户，请确认你要修改的账户\n");
            return;
        }
        printf("请输入你修改后的账户:   ");
        scanf("%s", name);
        if (!strcmp(ptr->data.name, name))
        {
            printf("新账号与原账号名相同\n");
            return;
        }
        revise_u_name(Flight_sys, &ptr->data, name);
        printf("修改成功,修改后的用户信息为\n");
        printf("账号:%s\t密码:%s\t用户等级:%d\t余额:%d\n", ptr->data.name, ptr->data.passwd, ptr->data.IDcard, ptr->data.value);

        break;
    case 2:
        printf("\t\t\t\t修改用户的密码\t\t\t\t\n");
        printf("请你输入要修改的账号:  ");
        scanf("%s", name);
        ptr = find_node_name(list_1, name);
        if (NULL == ptr)
        {
            printf("没有找到你要修改的账户，请确认你要修改的账户\n");
            return;
        }
        printf("请输入你修改后的密码:   ");
        scanf("%s", name);
        if (!strcmp(ptr->data.passwd, name))
        {
            printf("新密码与原密码相同");
            return;
        }
        revise_admin_pwd(Flight_sys, &ptr->data, name);
        printf("修改成功,修改后的用户信息为\n");
        printf("账号:%s\t密码:%s\t用户等级:%d\t余额:%d\n", ptr->data.name, ptr->data.passwd, ptr->data.IDcard, ptr->data.value);
        break;
    case 3:
        printf("\t\t\t\t修改用户的余额\t\t\t\t\n");
        printf("请你输入要修改的账号:  ");
        scanf("%s", name);
        ptr = find_node_name(list_1, name);
        if (NULL == ptr)
        {
            printf("没有找到你要修改的账户，请确认你要修改的账户\n");
            return;
        }
        printf("请输入你修改后的余额:   ");
        scanf("%d", &v);
        revise_admin_count(Flight_sys, &ptr->data, v);
        printf("修改成功,修改后的用户信息为\n");
        printf("账号:%s\t密码:%s\t用户等级:%d\t余额:%d\n", ptr->data.name, ptr->data.passwd, ptr->data.IDcard, ptr->data.value);
        break;
    case 4:
        printf("\t\t\t\t修改用户的等级\t\t\t\t\n");
        printf("请你输入要修改的账号:  ");
        scanf("%s", name);
        ptr = find_node_name(list_1, name);

        if (NULL == ptr)
        {
            printf("没有找到你要修改的账户，请确认你要修改的账户\n");
            return;
        }
        printf("用户等级分为\n");
        printf("1、普通用户\n");
        printf("2、银卡会员\n");
        printf("3、金卡会员\n");
        printf("4、白金会员\n");
        printf("请输入你修改后的用户等级:   ");
        scanf("%d", &num_2);
        revise_u_gread(Flight_sys, &ptr->data, num_2 + 1);
        printf("修改成功,修改后的用户信息为\n");
        printf("账号:%s\t密码:%s\t用户等级:%d\t余额:%d\n", ptr->data.name, ptr->data.passwd, ptr->data.IDcard, ptr->data.value);
        break;
    default:
        break;
    }
    list_2 = gread(Flight_sys, ptr->data);
    revise_node_name(list_2, ptr->data.name, ptr->data);
}
// 管理员菜单界面
void M_menu(FlightSystem Flight_sys, user_t data_2)
{
    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[34m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    int flag_1 = 0;
    while (1)
    {
        system("clear");
        printf("\t\t%s-------------------------------------------%s%s%s%s菜单界面%s%s-------------------------------------------%s\n", blue_bg, reset, red_bg, white_fg, bold, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        1️⃣  设定航班信息                                             2️⃣  浏览航班信息         %s|%s\n", blue_bg, reset, blue_bg, reset); // 增加航班信息  删除航班信息
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        3️⃣  查询航班信息                                             4️⃣  修改航班信息         %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        5️⃣  购票/退票                                                6️⃣  修改普通用户         %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        7️⃣  我的订单                                                 8️⃣  退出系统            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s---------------------------------------------------------------------------------------------%s\n", blue_bg, reset);
        printf("请输入你的选项：\n");
        int b;
        scanf("%d", &b);
        switch (b)
        {
        case 1:
            while (1)
            {
                system("clear");
                f_set_up_menu(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 2:
            while (1)
            {
                system("clear");
                print_forward_double_link_list(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 3:
            while (1)
            {
                system("clear");
                qurey_menu(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 4:
            while (1)
            {
                system("clear");
                modify_menu(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 5:
            while (1)
            {
                system("clear");
                const char *blue_bg = "\033[34m";  // 蓝色背景
                const char *white_fg = "\033[37m"; // 白色前景
                const char *reset = "\033[0m";     // 重置所有样式
                const char *bold = "\033[1m";      // 加粗文本
                const char *underline = "\033[4m"; // 下划线文本
                printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
                printf("│                                                                                    │\n");
                printf("│                                    %s%s%s购票/退票%s                                       │\n", red_bg, white_fg, bold, reset); // 标题行
                printf("│                                ─────────────────                                   │\n");                                        // 分割线
                printf("│                                                                                    │\n");
                printf("│                            1️⃣  购票            2️⃣  退票                              │\n"); // 选项行（居中对齐）
                printf("│                                                                                    │\n");
                printf("│                                                                                    │\n");
                printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
                printf("（请按数字键选择操作）                     \n");
                int num;
                scanf("%d", &num);
                getchar();
                if (1 == num)
                {
                    system("clear");
                    buy_ticket_menu(Flight_sys, &data_2);
                }
                else
                {
                    system("clear");
                    refund_ticket_menu(Flight_sys, &data_2, data_2.IDcard);
                }
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }
            break;
        case 6:
            while (1)
            {
                system("clear");
                revise_u_menu(Flight_sys, &data_2);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 7:
            while (1)
            {
                system("clear");
                printf("我的订单\n");
                getchar();

                if (data_2.ticket->len == 0)
                {
                    printf("你还没有订单，请先购票\n");
                }
                else
                {
                    printf_Sql_List(data_2.ticket);
                }
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }
            break;
        case 8:
            flag_1 = 1;
            break;
        }
        if (flag_1 == 1)
        {
            system("clear");
            fi();
            printf("退出成功，欢迎下次登录!\n");
            getchar();
            break;
        }
    }
}

// 用户修改密码
void revise_u_pwd(FlightSystem Flight_sys, user_t *data_2)
{
    char pwd[128];
    while (1)
    {
        printf("请输入你修改后的密码:   ");
        scanf("%s", pwd);
        if (!strcmp(data_2->passwd, pwd))
            printf("新密码与原密码相同");
        else
            break;
    }
    strcpy(data_2->passwd, pwd);
    printf("修改成功,修改后的用户信息为\n");
    printf("账号:%s\t密码:%s\t用户等级:%d\t余额:%d\n", data_2->name, data_2->passwd, data_2->IDcard, data_2->value);
    u_list *list_2 = gread(Flight_sys, *data_2);

    revise_node_name(list_2, data_2->name, *data_2);
    scanf_file((*data_2).IDcard, list_2);
}
// 用户充值金额
void revise_u_value(FlightSystem Flight_sys, user_t *data_2)
{
    printf("请输入你要充值的金额\n");
    int v;
    scanf("%d", &v);
    data_2->value += v;
    printf("充值成功\n");
    printf("充值后的余额为%d", data_2->value);
    if (10000 <= data_2->value && 15000 >= data_2->value && 3 > data_2->IDcard)
    {
        printf("恭喜你充值金额达到银卡会员，已自动为您升级为银卡会员\n");
        revise_u_gread(Flight_sys, data_2, 3);
        scanf_file((*data_2).IDcard, Flight_sys.SILVER_USER);
        return;
    }
    if (15000 <= data_2->value && 20000 >= data_2->value && 4 > data_2->IDcard)
    {
        printf("恭喜你充值金额达到金卡会员，已自动为您升级为金卡会员\n");
        revise_u_gread(Flight_sys, data_2, 4);
        scanf_file((*data_2).IDcard, Flight_sys.GOLD_USER);
        return;
    }
    if (20000 <= data_2->value && 5 > data_2->IDcard)
    {
        printf("恭喜你充值金额达到白金会员，已自动为您升级为白金会员\n");
        revise_u_gread(Flight_sys, data_2, 5);
        scanf_file((*data_2).IDcard, Flight_sys.PLATINUM_USER);
        return;
    }
    u_list *list_2 = gread(Flight_sys, *data_2);

    revise_node_name(list_2, data_2->name, *data_2);
    scanf_file((*data_2).IDcard, list_2);
}
// 用户菜单界面
void U_menu(FlightSystem Flight_sys, user_t data_2)
{
    int flag_1 = 0;
    const char *red_bg = "\033[41m";   // 红色背景
    const char *blue_bg = "\033[34m";  // 蓝色背景
    const char *white_fg = "\033[37m"; // 白色前景
    const char *reset = "\033[0m";     // 重置所有样式
    const char *bold = "\033[1m";      // 加粗文本
    const char *underline = "\033[4m"; // 下划线文本
    while (1)
    {
        system("clear");
        printf("\t\t%s-------------------------------------------%s%s%s%s菜单界面%s%s-------------------------------------------%s\n", blue_bg, reset, red_bg, white_fg, bold, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        1️⃣  浏览航班信息                                             2️⃣  查询航班信息         %s|%s\n", blue_bg, reset, blue_bg, reset); // 增加航班信息  删除航班信息
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        3️⃣  修改密码                                                 4️⃣  购票/退票            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        5️⃣  我的订单                                                 6️⃣  充值余额             %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s        7️⃣  退出系统                                                                         %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s|%s                                                                                            %s|%s\n", blue_bg, reset, blue_bg, reset);
        printf("\t\t%s----------------------------------------------------------------------------------------------%s\n", blue_bg, reset);
        printf("请输入你的选项：\n");
        int b;
        // getchar();
        scanf("%d", &b);
        switch (b)
        {
        case 1:
            while (1)
            {
                system("clear");
                print_forward_double_link_list(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 2:
            while (1)
            {
                system("clear");
                qurey_menu(Flight_sys.Flight_list);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 3:
            while (1)
            {
                system("clear");
                revise_u_pwd(Flight_sys, &data_2);

                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 4:
            while (1)
            {
                system("clear");
                const char *red_bg = "\033[41m";   // 红色背景
                const char *blue_bg = "\033[34m";  // 蓝色背景
                const char *white_fg = "\033[37m"; // 白色前景
                const char *reset = "\033[0m";     // 重置所有样式
                const char *bold = "\033[1m";      // 加粗文本
                const char *underline = "\033[4m"; // 下划线文本
                printf("┌────────────────────────────────────────────────────────────────────────────────────┐\n");
                printf("│                                                                                    │\n");
                printf("│                                    %s%s%s购票/退票%s                                       │\n", red_bg, white_fg, bold, reset); // 标题行
                printf("│                                ─────────────────                                   │\n");                                        // 分割线
                printf("│                                                                                    │\n");
                printf("│                            1️⃣  购票            2️⃣  退票                              │\n"); // 选项行（居中对齐）
                printf("│                                                                                    │\n");
                printf("│                                                                                    │\n");
                printf("└────────────────────────────────────────────────────────────────────────────────────┘\n"); // 底部边框
                printf("（请按数字键选择操作）                     \n");
                int num;
                scanf("%d", &num);
                getchar();
                if (1 == num)
                {
                    system("clear");
                    buy_ticket_menu(Flight_sys, &data_2);
                }
                else
                {
                    system("clear");
                    refund_ticket_menu(Flight_sys, &data_2, data_2.IDcard);
                }
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }
            break;
        case 5:
            while (1)
            {
                system("clear");
                printf("我的订单\n");
                getchar();

                if (data_2.ticket->len == 0)
                {
                    printf("你还没有订单，请先购票\n");
                }
                else
                {
                    printf_Sql_List(data_2.ticket);
                }
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }

            break;
        case 6:
            while (1)
            {
                system("clear");
                printf("金额充值\n");
                revise_u_value(Flight_sys, &data_2);
                printf("是否继续(y/n)\n");
                char num_1;
                getchar();
                scanf("%c", &num_1);
                if ('y' != num_1)
                {
                    break;
                }
            }
            break;
        case 7:
            flag_1 = 1;
            break;
        default:
            break;
        }
        if (flag_1 == 1)
        {
            system("clear");
            fi();
            printf("退出成功，欢迎下次登录!\n");
            // getchar();
            break;
        }
    }
}
// 二次操作写入用户文件
void scanf_file(int grade, u_list *list)
{
    switch (grade)
    {
    case 2:
        F_print(list, REGULAR_FILE);
        break;
    case 3:
        F_print(list, SILVER_FILE);
        break;
    case 4:
        F_print(list, GOLD_FILE);
        break;
    case 5:
        F_print(list, PLATINUM_FILE);
        break;
    }
}